org 0x7c00
xor ax, ax ; eax = 0
; 初始化段寄存器, 段地址全部设为0
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax

; 初始化栈指针
mov sp, 0x7c00
mov ax, 0xb800
mov gs, ax

section .bss
	pX resb 1
	pY resb 1
	dirX resb 1
	dirY resb 1
	color resb 1
	count resb 1
	;color1 resb 1
	;color2 resb 1
	
section .text
	global _start

_start:
	mov byte [pX],2
	mov byte [pY],0
	mov byte [dirX],1
	mov byte [dirY],1
	mov byte [color],0x12
	mov byte [count],0
	;mov byte [color1],0x0e
	;mov byte [color2],0x01
	mov ah,0
	mov al,0x03
	int 10h
	
main_loop:
	mov ah,0x02
	mov bh,0
	mov dl,[pX]
	mov dh,[pY]
	int 10h
	
	inc byte [count]
	cmp byte [count],5
	jl display
	
	
	mov al,[color]
	inc al
	and al,0x0f
	
	mov ah,al
	inc ah
	shl ah,4
	or al,ah
	mov [color],al
	;mov [count],0
	;mov al,[color1]
	;mov ah,[color2]
	;shl ah,2
	;or al,ah
	
	;inc byte [color1]
	;cmp byte [color1],0x0F
	;jle change
	;xor byte [color1],byte [color1]
	
	;change:
	;inc byte [color2]
	;cmp byte [color2],0x0F
	;jle display
	;xor byte [color2],byte [color2]
	
	
	display:
	mov ah,9
	mov bl,[color]
	mov al, '*'
	mov bh,0
	mov cx,1;0xFF
	int 10h
	
	
	
	
delay_loop:
	push ecx
	mov ecx,10000000
	delay: 
	dec ecx
	jnz delay
	
	mov al,[pX]
	mov bl,[dirX]
	add al,bl
	mov [pX],al
	
	mov al,[pY]
	mov bl,[dirY]
	add al,bl
	mov [pY],al
	
	cmp byte [pX],79
	je revX
	cmp byte [pX],0
	je revX
	
	cmp byte [pY],24
	je revY
	cmp byte [pY],0
	je revY
	
	jmp main_loop
	
revX:
	neg byte [dirX]
	jmp main_loop
	
revY:
	neg byte [dirY]
	jmp main_loop
	
times 510 - ($ - $$) db 0
db 0x55, 0xaa
